package com.franklin.ideaplugin.easytesting.editor;

import com.franklin.ideaplugin.easytesting.vfs.ExecuteMethodVirtualFile;
import com.intellij.openapi.fileEditor.FileEditor;
import com.intellij.openapi.fileEditor.impl.text.PsiAwareTextEditorProvider;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.annotations.NotNull;

/**
 * @author Franklin
 * @since 2023/07/31 20:55
 */
public abstract class BaseExecuteMethodEditorProvider extends PsiAwareTextEditorProvider {

    @Override
    public final boolean accept(@NotNull Project project, @NotNull VirtualFile file) {
        return file instanceof ExecuteMethodVirtualFile && this.accept(project,(ExecuteMethodVirtualFile)file);
    }

    @Override
    public final @NotNull FileEditor createEditor(@NotNull Project project, @NotNull VirtualFile file) {
        return buildEditor(project, (ExecuteMethodVirtualFile) file);
    }

    protected abstract @NotNull FileEditor buildEditor(@NotNull Project project, @NotNull ExecuteMethodVirtualFile executeMethodVirtualFile);

    /**
     * 是否是可执行的文件
     * @param project
     * @param executeMethodVirtualFile
     * @return
     */
    protected boolean accept(@NotNull Project project, @NotNull ExecuteMethodVirtualFile executeMethodVirtualFile){
        return true;
    }
}
